<#import "spring.ftl" as spring />
<#import "/inspector-time-macros.ftl" as imacro />

<html>
<head>
	<title>Schedule your inspection</title>
</head>
<body>

<#include "schedulebreadcrumb.ftl">


<div id="content">
	<#-- grab the first list of schedule days so we can determine the range we're working with -->
	<#assign rangeDays = inspectorDays?values[0] />
	<#assign startDay = rangeDays[0] />
	<#assign endDay = rangeDays[rangeDays?size-1] />
		
	<#if inProgressInspection.inspectionTime??>
		<div id="infoBox">
			<table>
			<tr>
				<td><b>Home Inspector:</b></td>
				<td>${inProgressInspection.inspector.name} of ${inspectorCompany.name}</td>
			</tr>
			<tr>
				<td><b>Property Address:</b></td>
				<td>${inProgressInspection.property.location.street1}, ${inProgressInspection.property.location.city}</td>
			</tr>
			<tr>
				<td><b>Time of inspection:</b></td>
				<td>${inProgressInspection.inspectionTime?date} at ${inProgressInspection.inspectionTime?time?string.short}</td>
			</tr>
			<tr>
				<td><b>Inspection fee:</b></td>
				<td>$${inProgressInspection.inspectionFee}</td>
			</tr>
			</table>	
		</div>
	<#else>
		<div id="infoBox">
			<table>
			<tr>
				<td><b>Home Inspector:</b></td>
				<td>${inspectorCompany.name}</td>
			</tr>
			</table>	
		</div>
	</#if>
	<br style="clear: both" />
	
	<p>The following inspectors and inspection times are available.  Please select an appropriate time by clicking one of the time buttons in the results below.</p>	
	<#include "include-pickTimeNavigation.ftl">
	<br/>
	<div class="resultsList">
	
		<#-- loop thru each of the rangeDays to see if any of the inspectors has an available timeslot -->
		<#list 0..(rangeDays?size -1) as dayCounter>
		
			<div class="resultsList">
				
				<#assign timeslotDisplayed = false />
				
				<!-- loop thru each inspector and see if there's a timeslot(s) in this day -->
				<#list inspectors as inspector>
					
					<#assign inspectorDaysList = inspectorDays[inspector.id] />
					<#assign thisDay = inspectorDaysList[dayCounter] />
					<#assign isToday = false />
					<#if (thisDay.isSameDate(todayCal))>
						<#assign isToday = true />
					</#if>
		
					<#if (thisDay.hasAvailableTimeslot() && !isToday) >
						<#if !timeslotDisplayed>
							<label>${rangeDays[dayCounter].toDate()?string("EEEE, MMM d")?upper_case}</label>
						</#if>	
					
						<#assign timeslotDisplayed = true />
						<div class="resultsListRow">
							<div class="resultsListBullet"></div>
							<span class="resultsListText">${inspector.name.first?upper_case} ${inspector.name.last?upper_case}:</span>
							<span class="resultsListDivider">|</span>
							<span class="resultsListSubtext"><a href="inspector.html?id=${inspector.id}">VIEW PROFILE</a></span>
							
								<#list thisDay.timeslots as timeslot>
									<#if timeslot.available>
										<a href="schedule2-pi.html?day=<@imacro.navDateFormat thisDay.toDate() />&hour=${timeslot.startTime.hour}&minute=${timeslot.startTime.minute}&inspectorId=${inspector.id}" class="resultsListTimeslot">${timeslot.startTime}</a>
									</#if>
								</#list>
						</div> <!-- /resultsListRow -->
						
					</#if>
					
				</#list> <#-- end inspectors loop -->
				
				<#-- Don't show empty days
				<#if !timeslotDisplayed>
					<div class="resultsListRow">
						<div class="resultsListText">
							<#if isToday == true>
							 	SORRY, NO SAME-DAY BOOKINGS. PLEASE CALL FOR INQUIRES.
							<#else>
								NO TIME AVAILABLE.
							</#if>	
						</div>
					</div> 
				</#if>
				-->
			
			</div>
		
		</#list>
	
	</div> <!-- /resultsList -->	
	<#include "include-pickTimeNavigation.ftl">
	<hr/>
	<#if (Session.fromSearch)??>
		<#assign fromSearchParam="&fromSearch=true" />
	<#else>
		<#assign fromSearchParam="" />
	</#if>
	<#if (inProgressInspection.inspectionTime)?? >
		<p><i>You have scheduled an appointment for ${inProgressInspection.inspectionTime?date} ${inProgressInspection.inspectionTime?time}. 
		    To keep this appointment time and fill out your remaining information, please click <b>CONTINUE</b> below.</i></p>
		<a href="schedule1.html?wizardStarted=true${fromSearchParam}" class="navBack">BACK</a>
		<a href="schedule2-rt.html" class="navFwd">CONTINUE</a></p>
	<#else>
		<a href="schedule1.html?wizardStarted=true${fromSearchParam}" class="navBack">BACK</a>
	</#if>
	<br class="clearBoth" />
	
	
</div> <!-- /content -->
</body>
</html>
